package com.youku
{
   import flash.display.Sprite;
   import com.youku.interfaces.IFSOProxy;
   import com.youku.utils.FSOManager;
   import com.youku.data.PlayerConstant;
   
   public class FSOProxy extends Sprite implements IFSOProxy
   {
      
      public function FSOProxy() {
         super();
      }
      
      public static const YOUKU_FSO_PROXY:String = "YOUKU_FSO_PROXY";
      
      private var _youkuFSO:FSOManager;
      
      public function init() : void {
         this._youkuFSO = new FSOManager(YOUKU_FSO_PROXY,"/");
      }
      
      public function setMute(param1:Boolean) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         this._youkuFSO.save("mute",param1,null,true);
      }
      
      public function getMute() : Boolean {
         if(this._youkuFSO == null)
         {
            return false;
         }
         var _loc1_:Object = this._youkuFSO.load("mute");
         if(_loc1_ != null)
         {
            return _loc1_ == true;
         }
         return false;
      }
      
      public function setVolume(param1:Number) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         this._youkuFSO.save("volume",param1,null,true);
      }
      
      public function getVolume() : Number {
         if(this._youkuFSO == null)
         {
            return 0.5;
         }
         var _loc1_:Object = this._youkuFSO.load("volume");
         if(!(_loc1_ == null) && !isNaN(Number(_loc1_)))
         {
            return Number(_loc1_);
         }
         return 0.5;
      }
      
      public function setContinuous(param1:Boolean) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         this._youkuFSO.save("continuous",param1,null,true);
      }
      
      public function getContinuous() : Boolean {
         if(this._youkuFSO == null)
         {
            return true;
         }
         var _loc1_:Object = this._youkuFSO.load("continuous");
         if(_loc1_ != null)
         {
            return _loc1_ == true;
         }
         return true;
      }
      
      public function setJump(param1:Boolean) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         this._youkuFSO.save("jump",param1,null,true);
      }
      
      public function getJump() : Boolean {
         if(this._youkuFSO == null)
         {
            return true;
         }
         var _loc1_:Object = this._youkuFSO.load("jump");
         if(_loc1_ != null)
         {
            return _loc1_ == true;
         }
         return true;
      }
      
      public function setDefaultQuality(param1:String) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         var _loc2_:String = param1 == "1080P"?"high":param1;
         this._youkuFSO.save("quality",_loc2_,null,true);
      }
      
      public function getDefaultQuality() : String {
         if(this._youkuFSO == null)
         {
            return PlayerConstant.QUALITY_AUTO;
         }
         var _loc1_:Object = this._youkuFSO.load("quality");
         if(_loc1_ != null)
         {
            return _loc1_ as String;
         }
         return PlayerConstant.QUALITY_AUTO;
      }
      
      public function setDefaultQualityTime(param1:Number) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         this._youkuFSO.save("qualityTime",param1,null,true);
      }
      
      public function getDefaultQualityTime() : Number {
         if(this._youkuFSO == null)
         {
            return 0;
         }
         var _loc1_:Object = this._youkuFSO.load("qualityTime");
         if(_loc1_ != null)
         {
            return _loc1_ as Number;
         }
         return 0;
      }
      
      public function setDefaultVoice(param1:String) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         this._youkuFSO.save("voice",param1,null,true);
      }
      
      public function getDefaultVoice() : String {
         if(this._youkuFSO == null)
         {
            return "default";
         }
         var _loc1_:Object = this._youkuFSO.load("voice");
         if(_loc1_ != null)
         {
            return _loc1_ as String;
         }
         return "default";
      }
      
      public function setGUID(param1:String) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         this._youkuFSO.save("GUID",param1,null,true);
      }
      
      public function getGUID() : String {
         if(this._youkuFSO == null)
         {
            return null;
         }
         var _loc1_:Object = this._youkuFSO.load("GUID");
         if(_loc1_ != null)
         {
            return _loc1_ as String;
         }
         return null;
      }
      
      public function saveUserWatchingRecord(param1:String, param2:Number) : void {
         if(this._youkuFSO == null)
         {
            return;
         }
         var _loc3_:Object = this._youkuFSO.load("playingRecords");
         if(_loc3_ == null)
         {
            _loc3_ = new Object();
         }
         _loc3_[param1] = 
            {
               "position":param2,
               "time":new Date().getTime()
            };
         this._youkuFSO.save("playingRecords",_loc3_,null,true);
      }
      
      public function removeUserWatchingRecord(param1:String) : void {
         if(this._youkuFSO == null)
         {
            return;
         }
         var _loc2_:Object = this._youkuFSO.load("playingRecords");
         if(_loc2_ != null)
         {
            if(_loc2_[param1] != null)
            {
               delete _loc2_[param1];
               this._youkuFSO.save("playingRecords",_loc2_,null,true);
            }
         }
      }
      
      public function hasUserWatchingRecord(param1:String) : Boolean {
         if(this._youkuFSO == null)
         {
            return false;
         }
         var _loc2_:Object = this._youkuFSO.load("playingRecords");
         if(_loc2_ != null)
         {
            if(!(_loc2_[param1] == null) && !(_loc2_[param1] === undefined))
            {
               return true;
            }
         }
         return false;
      }
      
      public function getUserWatchingRecord(param1:String) : Object {
         var _loc3_:Object = null;
         if(this._youkuFSO == null)
         {
            return null;
         }
         var _loc2_:Object = this._youkuFSO.load("playingRecords");
         if(_loc2_ != null)
         {
            if(!(_loc2_[param1] == null) && !(_loc2_[param1] === undefined))
            {
               _loc3_ = _loc2_[param1];
               if(_loc3_.position != null)
               {
                  return 
                     {
                        "position":_loc3_.position,
                        "time":_loc3_.time
                     };
               }
            }
         }
         return null;
      }
      
      public function clearUserWatchingRecord() : void {
         var _loc4_:String = null;
         var _loc5_:Object = null;
         if(this._youkuFSO == null)
         {
            return;
         }
         var _loc1_:Object = this._youkuFSO.load("playingRecords");
         var _loc2_:Array = [];
         if(_loc1_ != null)
         {
            for(_loc4_ in _loc1_)
            {
               _loc5_ = {};
               _loc5_.videoid = _loc4_;
               _loc5_.position = _loc1_[_loc4_].position;
               _loc5_.time = _loc1_[_loc4_].time;
               _loc2_.push(_loc5_);
            }
         }
         if(_loc2_.length <= 30)
         {
            return;
         }
         _loc2_.sort(this.sortOnTime,Array.DESCENDING);
         _loc2_ = _loc2_.slice(0,30);
         _loc1_ = new Object();
         var _loc3_:* = 0;
         while(_loc3_ < _loc2_.length)
         {
            _loc5_ = _loc2_[_loc3_];
            _loc1_[_loc5_.videoid] = 
               {
                  "position":_loc5_.position,
                  "time":_loc5_.time
               };
            _loc3_++;
         }
         this._youkuFSO.save("playingRecords",_loc1_,null,true);
      }
      
      private function sortOnTime(param1:Object, param2:Object) : Number {
         if(param1.time > param2.time)
         {
            return 1;
         }
         if(param1.time < param2.time)
         {
            return -1;
         }
         return 0;
      }
      
      public function saveDownloadSpeeds(param1:String, param2:Array) : void {
         if(this._youkuFSO == null)
         {
            return;
         }
         var _loc3_:Object = this._youkuFSO.load("speeds");
         if(_loc3_ == null)
         {
            _loc3_ = new Object();
         }
         if(_loc3_[param1] === undefined || _loc3_[param1] == null)
         {
            _loc3_[param1] = new Array();
         }
         _loc3_[param1] = param2;
         this._youkuFSO.save("speeds",_loc3_,null,true);
      }
      
      public function saveDownloadSpeed(param1:String, param2:Number) : void {
         if(this._youkuFSO == null)
         {
            return;
         }
         var _loc3_:Object = this._youkuFSO.load("speeds");
         if(_loc3_ == null)
         {
            _loc3_ = new Object();
         }
         if(_loc3_[param1] === undefined || _loc3_[param1] == null)
         {
            _loc3_[param1] = new Array();
         }
         _loc3_[param1].push(
            {
               "s":param2,
               "time":new Date().getTime()
            });
         this._youkuFSO.save("speeds",_loc3_,null,true);
      }
      
      public function getDownloadSpeed(param1:String) : Array {
         if(this._youkuFSO == null)
         {
            return [];
         }
         var _loc2_:Object = this._youkuFSO.load("speeds");
         if(_loc2_ == null)
         {
            return [];
         }
         var _loc3_:Array = new Array();
         if(!(_loc2_[param1] === undefined) && !(_loc2_[param1] == null))
         {
            _loc3_ = _loc2_[param1] as Array;
         }
         return _loc3_;
      }
      
      public function saveADHoldingInfo(param1:Object) : void {
         if(this._youkuFSO == null)
         {
            return;
         }
         this._youkuFSO.save("adHoldingInfo",param1,null,true);
      }
      
      public function getADHoldingInfo() : Object {
         if(this._youkuFSO == null)
         {
            return {};
         }
         var _loc1_:Object = this._youkuFSO.load("adHoldingInfo");
         if(_loc1_ == null)
         {
            return {};
         }
         return _loc1_;
      }
      
      public function saveADRefreshInfo(param1:Object) : void {
         if(this._youkuFSO == null)
         {
            return;
         }
         this._youkuFSO.save("adRefreshInfo",param1,null,true);
      }
      
      public function getADRefreshInfo() : Object {
         if(this._youkuFSO == null)
         {
            return {};
         }
         var _loc1_:Object = this._youkuFSO.load("adRefreshInfo");
         if(_loc1_ == null)
         {
            return {};
         }
         return _loc1_;
      }
      
      public function saveUpDownInfo(param1:String, param2:Number, param3:String) : void {
         var _loc5_:* = NaN;
         var _loc6_:* = 0;
         var _loc7_:Object = null;
         if(this._youkuFSO == null)
         {
            return;
         }
         var _loc4_:Array = this._youkuFSO.load("upDown") as Array;
         if(_loc4_ == null || _loc4_.length == 0)
         {
            _loc4_ = new Array();
         }
         else
         {
            _loc5_ = new Date().getTime();
            _loc6_ = _loc4_.length - 1;
            while(_loc6_ > -1)
            {
               _loc7_ = _loc4_[_loc6_];
               if(_loc5_ - Number(_loc7_.time) > 24 * 60 * 60 * 1000)
               {
                  _loc4_.splice(_loc6_,1);
               }
               _loc6_--;
            }
         }
         _loc4_.push(
            {
               "vid":param1,
               "time":param2,
               "type":param3
            });
         this._youkuFSO.save("upDown",_loc4_,null,true);
      }
      
      public function getUpDownInfo() : Array {
         if(this._youkuFSO == null)
         {
            return new Array();
         }
         var _loc1_:Array = this._youkuFSO.load("upDown") as Array;
         if(_loc1_ == null)
         {
            return new Array();
         }
         return _loc1_;
      }
      
      public function saveADTimeInfo(param1:Number) : void {
         if(this._youkuFSO == null)
         {
            return;
         }
         this._youkuFSO.save("ADTime",param1,null,true);
      }
      
      public function getADTimeInfo() : Number {
         if(this._youkuFSO == null)
         {
            return 0;
         }
         var _loc1_:Object = this._youkuFSO.load("ADTime");
         if(_loc1_ == null)
         {
            return 0;
         }
         var _loc2_:Number = _loc1_ as Number;
         return _loc2_;
      }
      
      public function saveLoopSetting(param1:Boolean) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         this._youkuFSO.save("loop",param1,null,true);
      }
      
      public function getLoopSetting() : Boolean {
         if(this._youkuFSO == null)
         {
            return false;
         }
         var _loc1_:Object = this._youkuFSO.load("loop");
         if(_loc1_ != null)
         {
            return _loc1_ as Boolean;
         }
         return false;
      }
      
      public function saveScreenMode(param1:String) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         this._youkuFSO.save("screen",param1,null,true);
      }
      
      public function getScreenMode() : String {
         var _loc2_:String = null;
         if(this._youkuFSO == null)
         {
            return PlayerConstant.SCREEN_MODE_100;
         }
         var _loc1_:Object = this._youkuFSO.load("screen");
         if(_loc1_ != null)
         {
            _loc2_ = _loc1_ as String;
            if(_loc2_ == PlayerConstant.SCREEN_MODE_100 || _loc2_ == PlayerConstant.SCREEN_MODE_75 || _loc2_ == PlayerConstant.SCREEN_MODE_50 || _loc2_ == PlayerConstant.SCREEN_MODE_FULL)
            {
               return _loc2_;
            }
            return PlayerConstant.SCREEN_MODE_100;
         }
         return PlayerConstant.SCREEN_MODE_100;
      }
      
      public function saveTipsSetting(param1:String) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         var _loc2_:Object = this._youkuFSO.load("tips");
         if(_loc2_ == null)
         {
            _loc2_ = {};
         }
         _loc2_[param1] = true;
         this._youkuFSO.save("tips",_loc2_,null,true);
      }
      
      public function getTipsSetting(param1:String) : Boolean {
         if(this._youkuFSO == null)
         {
            return false;
         }
         var _loc2_:Object = this._youkuFSO.load("tips");
         if(_loc2_ != null)
         {
            return _loc2_[param1] as Boolean;
         }
         return false;
      }
      
      public function saveAccTime(param1:Number) : void {
         if(!this._youkuFSO)
         {
            return;
         }
         var _loc2_:Object = this._youkuFSO.load("acc");
         if(_loc2_ == null)
         {
            _loc2_ = {};
         }
         _loc2_.time = param1;
         this._youkuFSO.save("acc",_loc2_,null,true);
      }
      
      public function getAccTime() : Number {
         if(this._youkuFSO == null)
         {
            return 0;
         }
         var _loc1_:Object = this._youkuFSO.load("acc");
         if(_loc1_ != null)
         {
            return _loc1_.time;
         }
         return 0;
      }
   }
}
